#include <stdio.h>
#include <unistd.h>
#include <string.h>
#include <stdlib.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
int main()
{
   /*打开文件*/
   const char *filename = "./record.txt";
   int fd = open(filename, O_RDWR | O_CREAT,0644);
   if(fd == -1)
   {
      perror("open error");
      exit(-1);
   }
    printf("fd = %d\n",fd);
    /*将文件内容读到内存中*/
    // char buffer[32] = {0};
    // int readBytes = read(fd,buffer,sizeof(buffer) -1);
    // printf("readBytes = %d,\tbuffer = %s\n",readBytes,buffer);

    char buffer[128] = {0};
    int requestBytes = sizeof(buffer) - 1;
    while(1)
    {
        int readBytes = read(fd,buffer,requestBytes);
        if((readBytes <requestBytes) || readBytes == 0)
        {
             printf("%s\n",buffer);
             break;
        }
        printf("%s\n",buffer);
        /*清除缓冲区*/
        memset(buffer,0,sizeof(buffer));
    }
    /*关闭文件*/
    close(fd);
    return 0;
}
